#include "DopplerDrawAScan.h"
#include <QImage>
#include <QPainter>

extern volatile unsigned char  data[1024 * 2]  ;
void DopplerDrawAScan::Draw(QImage* pImage_)
{
    if(!pImage_)  return ;
    volatile unsigned char* _pData = data ; //m_cInfo.pData  ;
    int _nPointQty = m_cInfo.nPointQty ;

    double _nHeight  = (double)pImage_->height() - 1;
    double _nWidth   = (double)pImage_->width()  - 1;
    //qDebug("[%8x]  %f %f" , (int)pImage_ ,_nWidth , _nHeight);

    QPainter painter(pImage_) ;

    int i ,  j ;
    QPen pen ;
    pen.setWidth(0);
    painter.setPen(QPen(Qt::black));
    painter.drawLines(lines);
    lines.clear();


    painter.setPen(QPen(Qt::yellow));
    double pos1 , pos2 , pos3 , pos4 ;
    for(i = 0 , j = 1; j < _nPointQty  ; i++ , j++)
    {
        pos1 = i * _nWidth / _nPointQty  ;
        pos2 = _pData[i] * _nHeight / 255 ;
        pos3 = j * _nWidth / _nPointQty  ;
        pos4 = _pData[j] * _nHeight / 255 ;
        lines.append(QLineF(pos1 , _nHeight - pos2, pos3 , _nHeight - pos4));
    }
    painter.drawLines(lines);

    return  ;
}


void DopplerDrawAScan::SetColor(QColor* color_ , A_SCAN_LINE_TYPE eLineType_ )
{
    if(eLineType_ >= A_SCAN_LINE_TYPE_MAX)  return  ;
    color[eLineType_]  = *color_  ;
}

void DopplerDrawAScan::EndAbleLineDrawing(A_SCAN_LINE_TYPE eLineType_ , bool enalbe_ )
{
    if(eLineType_ == A_SCAN_DRAW_LIMIT)
    {
        bDrawLimit = enalbe_;
        if(enalbe_)
        {
            memset((void*) aLimitHigh , 0 , sizeof(int)* A_SCAN_LIMIT_BUFF_SIZE) ;
            memset((void*) aLimitLow  , 0 , sizeof(int)* A_SCAN_LIMIT_BUFF_SIZE) ;
        }
    }

    if(eLineType_ == A_SCAN_DRAW_FILL)
    {
        bDrawFill  = enalbe_ ;
    }
}
